package com.mrduan.otgfilemanager.ui_sdcard.video;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.bumptech.glide.Glide;
import com.mrduan.otgfilemanager.Config;
import com.mrduan.otgfilemanager.R;
import com.shike.baselibrary.activity.BaseActivity;

import java.io.File;

import cn.jzvd.JZVideoPlayer;
import cn.jzvd.JZVideoPlayerStandard;

public class VideoPlayActivity extends AppCompatActivity {

    private String filePath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContentView());

        initBindWidget();

        initListener();

        initData();
    }

    public int getContentView() {
        return R.layout.activity_video_play;
    }

    public void initBindWidget() {

    }

    public void initListener() {

    }

    public void initData() {
        filePath = getIntent().getStringExtra("path");

        String imgPath = "";
        String videoPath = "";
        String title = "";

        File file = new File(filePath);
        File[] files = file.listFiles();
        for (File f : files) {
            if (Config.isVideo(f)) {
                videoPath = f.getPath();
                title = f.getName();
            } else {
                imgPath = f.getPath();
            }
        }

        if (imgPath.length() > 0 && videoPath.length()>0 && title.length()>0) {
            JZVideoPlayerStandard jzVideoPlayerStandard = (JZVideoPlayerStandard) findViewById(R.id.videoplayer);
            jzVideoPlayerStandard.startFullscreen(this, JZVideoPlayerStandard.class, videoPath, title);
            Glide.with(this)
                    .load(imgPath)
                    .into(jzVideoPlayerStandard.thumbImageView);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        JZVideoPlayer.releaseAllVideos();
    }
}
